struct Foo;

// Implements a destructor for Foo.
impl Drop for Foo {
    fn drop(&mut self) {
        println!("dropped");
    }
}

fn baz(condition: bool) -> Result<(), ()> {
    if condition {
        Err(())
    } else {
        Ok(())
    }
}

fn bar(condition: bool) -> Result<(), ()> {
    // The dtor of _exit will run however the function `bar` is exited.
    let _exit = Foo;
    // An implicit return with `?` operator.
    baz(condition)?;

    // A normal return.
    Ok(())
}

fn main() -> Result<(), ()> {
    {
        bar(false)?;
    }

    println!();

    {
        bar(true)?;
    }

    Ok(())
}
